package com.chw.user.controller;

import com.chw.common.exception.ParamExcption;
import com.chw.common.returnData.ReturnData;
import com.chw.user.entity.po.User;
import com.chw.user.service.UserService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("user/")
//@CrossOrigin 跨域注解
public class UserController {
        @Resource
    private UserService userService;

      @RequestMapping("queryAllData")
    public ReturnData queryAllData(Integer a){
            if (a==null){
                throw  new ParamExcption();
            }


            return ReturnData.success( userService.queryAllData());
        }
        @RequestMapping("sendemail")
    public ReturnData sendemail (String email) throws Exception {

           Integer ma= userService.equalsEmail(email);
            return ReturnData.success(ma);
        }
        @RequestMapping("createData")
        public ReturnData createData (User user)  {

            Integer ma= userService.createData(user);
            return ReturnData.success(ma);
        }
        @RequestMapping("validatecode")
    public ReturnData validatecode(String email ,String code){
            Integer ma= userService.validatecode(email,code);

          return ReturnData.success(ma);
        }
        @RequestMapping("login")
    public ReturnData login(User user){


          return ReturnData.success( userService.login(user));
        }

}
